package com.kly.sc.api.infras.enums;

import com.fqgj.exception.enums.ErrorCodeEnum;
import org.springframework.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * @author poyangchen
 */
public enum BasicErrorCodeEnum implements ErrorCodeEnum {

    SUCCESS(0, "SUCCESS", HttpStatus.OK),
    OPEN_API_SUCCESS(200, "SUCCESS", HttpStatus.OK),
    INTERNAL_SERVER_ERROR(90000, "Internal server error", HttpStatus.INTERNAL_SERVER_ERROR),
    PARAM_VALID_ERROR(90001, "Parameter validation failed", HttpStatus.INTERNAL_SERVER_ERROR),
    PARAM_RESOLVE_ERROR(90002, "Parameter resolution exception", HttpStatus.INTERNAL_SERVER_ERROR),
    UNKNOW_ERROR(90012, "Operation failed. Please try again later.", HttpStatus.INTERNAL_SERVER_ERROR),
    MOTAN_SERVICE_ERROR(90023, "Internal server error", HttpStatus.INTERNAL_SERVER_ERROR),
    CLICK_ONLY_ONCE(90024, "Please click only once.", HttpStatus.INTERNAL_SERVER_ERROR),
    NO_ACCESS_RIGHT(10000, "Access Forbidden", HttpStatus.FORBIDDEN);
    private Integer code;

    private String desc;

    private HttpStatus httpStatus;

    BasicErrorCodeEnum(Integer code, String desc,
                       HttpStatus httpStatus) {
        this.code = code;
        this.desc = desc;
        this.httpStatus = httpStatus;
    }

    public Map<String, Object> map() {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("code", code);
        result.put("desc", desc);
        return result;
    }

    public Map<String, Object> map(String message) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("code", code);
        if (message != null) {
            result.put("desc", message + desc);
        }
        return result;
    }

    public String toString() {
        return code + ":" + desc;
    }

    public Integer getCode() {
        return code;
    }

    public ErrorCodeEnum setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getDesc() {
        return desc;
    }

    /****
     * 错误信息
     * @return
     */
    @Override
    public String getMsg() {
        return desc;
    }

    public ErrorCodeEnum setDesc(String desc) {
        this.desc = desc;
        return this;
    }

    public HttpStatus getHttpStatus() {
        return httpStatus;
    }

    public ErrorCodeEnum setHttpStatus(HttpStatus httpStatus) {
        this.httpStatus = httpStatus;
        return this;
    }
}